/***赵晓莉***/
require(["jquery","template","bootstrap3.min","bbcare","scprit/followup/app/comm/page/page.js","scprit/department/view/template/monitorList-tem.js"],function($,template,bootstrap,$bb,$page,$tpl) {
    var URL = $bb.baseUrl("department")+"followup/service";
    var count=20;//每页展示的患者个数
    $bb.ajax({
        url: URL + "/patient/familyreport/patientDataStatistics",
        type: "post",
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        data: JSON.stringify({
            data: {
                "type":"1"
            }
        }),
        success: function (data) {
            var watchList=$(".monitor-report-list>div");
            watchList.eq(0).find(".monitor-report-val").html(data.data.dayTestPatients);
            watchList.eq(1).find(".monitor-report-val").html(data.data.totalTestPatients);
            watchList.eq(2).find(".monitor-report-val").html(data.data.abnormalTimes);
            watchList.eq(3).find(".monitor-report-val").html(data.data.totalTestTimes);
            $(".monitor-report-footing").find(".totalNum").html(data.data.totalTestTimes);
        },
        error: function (data) {}
    });

    function getTem(page,rows){
        $bb.ajax({
            url: URL + "/patient/bodyTemperature/patientListqry",
            type: "post",
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            data: JSON.stringify({
                data: {
                    "page":page,
                    "rows":rows
                }
            }),
            success: function (data) {
                var pages=Math.ceil(data.total/rows);
                var value=$tpl.timeLong(data.rows,"timeLong","userName");
                $tpl.listInit({"id":"#monitor-user-box2","data":value});
                var emptyLis='';
                if(value.length<count){
                    for(var i=0;i<count-value.length;i++){
                        emptyLis+='<div class="monitor-user-card monitor-temperature"></div>';
                    }
                }
                $("#monitor-user-box2").append(emptyLis);
                $page.init({
                    id:"btn-toolbar",
                    pagesAll:pages,
                    page:page
                });
                $("#btn-toolbar .btn").click(function(){
                    var text = $(this).text();
                    page = $page.getPageActive({
                        "pageClick":text,
                        "page":page,
                        "pagesAll":pages
                    });
                    getTem(page,rows);
                });
            },
            error: function (data) {}
        });
    }
    getTem("1",count);

    $("#monitor-user-box2").on("click",".monitor-user-card",function(){
        var userId=$(this).attr("id");
        var gender=$(this).attr("gender");
        var obj={
            "userId":userId,
            "gender":gender
        };
        if(userId){
            $bb.openPage("physicalExaminationAnalysisReport",obj);
        }
    });

    $("#getAll").click(function(){
        $("#key").val("");
        getTem("1",count);
    });

    $(".input-group-addon").click(function(){
        var key=$("#key").val();
        toSearch(key,count,1);
    });
    $("#key").on("input propertychange",function(){
        var key=$.trim($(this).val());
        toSearch(key,count,1);
    });
    function toSearch(key,rows,page){
        $bb.ajax({
            url: URL + "/patient/bodyTemperature/patientListqry",
            type: "post",
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            data: JSON.stringify({
                data: {
                    "page":page,
                    "rows":rows,
                    "userName":key
                }
            }),
            success: function (data) {
                var pages=Math.ceil(data.total/rows);
                var value=$tpl.timeLong(data.rows,"timeLong","userName");
                $tpl.listInit({"id":"#monitor-user-box2","data":value});
                var emptyLis='';
                if(value.length<count){
                    for(var i=0;i<count-value.length;i++){
                        emptyLis+='<div class="monitor-user-card monitor-temperature"></div>';
                    }
                }
                $("#monitor-user-box2").append(emptyLis);
                $page.init({
                    id:"btn-toolbar",
                    pagesAll:pages,
                    page:page
                });
                $("#btn-toolbar .btn").click(function(){
                    var text = $(this).text();
                    page = $page.getPageActive({
                        "pageClick":text,
                        "page":page,
                        "pagesAll":pages
                    });
                    toSearch(key,rows,page);
                });
            },
            error: function (data) {}
        });
    }
});